package com.mxm.app.myapplication;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.mxm.app.myapplication.tools.Tools;

public class Test2 extends AppCompatActivity {

    private TextView text1,text2;
    private Button but1;
    private static Tools t;
    private static String url;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
                System.out.println(msg.toString());
                text2.setText(msg.obj.toString());
        }
    };
    static {
        t = new Tools();
    }
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.test2);
        text1 = findViewById(R.id.test2_view1);
        text2 = findViewById(R.id.test2_view2);
        but1 = findViewById(R.id.test2_but1);

        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                url =text1.getText().toString();
                System.out.println(url);
                new Thread(){
                    @Override
                    public void run() {
                        String html = t.URL_Get(url,null);
                        handler.hasMessages(1,html);
//                        text2.setText(html);
                    }
                }.start();
            }
        });
    }
}
